package com.mjt.admin.controller;


import com.mjt.admin.dto.TreeDto;
import com.mjt.admin.model.RespBean;
import com.mjt.admin.model.RespDataBean;
import com.mjt.admin.pojo.GoodsType;
import com.mjt.admin.service.IGoodsTypeService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 商品类别表 前端控制器
 * </p>
 *
 * @author 莫某人
 * @since 2021-11-01
 */
@Controller
@RequestMapping("/goodsType")
public class GoodsTypeController {
    @Resource
    private IGoodsTypeService goodsTypeService;

    @RequestMapping("/queryAllGoodsTypes")
    @ResponseBody
   public List<TreeDto> queryAllGoodsTypes(){
       return goodsTypeService.queryAllGoodsTypes();
   }


   @RequestMapping("index")
   public String index(){
        return "/goodsType/goods_type";
   }
   
   
    /**
     * @description 获取分类列表
     * @author 莫某人
     * @date 10:15 2021/11/3 
     * @return {@link RespDataBean< GoodsType>}
     **/
   @RequestMapping("list")
   @ResponseBody
   public RespDataBean<GoodsType> goodsTypeList()
   {
        return goodsTypeService.goodsTypeList();
   }

   /**
    * @description 打开分类添加页面
    * @author 莫某人
    * @date 10:21 2021/11/3
    * @return {@link String}
    **/
   @RequestMapping("addGoodsTypePage")
   public String addGoodsTypePage(Integer pId, Model model){
       model.addAttribute("pId",pId);
       return "goodsType/add";
   }

   @RequestMapping("save")
   @ResponseBody
   public RespBean saveGoodsType(GoodsType goodsType){
       //添加分类
       goodsTypeService.saveGoodsTypePage(goodsType);

       return RespBean.success("添加成功");
   }


   @RequestMapping("delete")
   @ResponseBody
   public RespBean deleteGoodsType(Integer id){
       goodsTypeService.deleteGoodsType(id);
       return RespBean.success("删除成功");

   }





}
